package com.yoo.ons.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.yoo.ons.R
import com.yoo.ons.model.PurchaseMemberModel
import com.yoo.ons.util.loadThumbnails
import com.youth.banner.adapter.BannerAdapter

class PurchaseMemberBannerAdapter(
    val context: Context,
    val data: List<PurchaseMemberModel>,
) : BannerAdapter<PurchaseMemberModel, PurchaseMemberBannerAdapter.BannerViewHolder>(data) {
    val load = arrayListOf<Int>()
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_dialog_banner_member_purchase,null)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        view.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        return BannerViewHolder(view)
    }

    override fun onBindView(holder: BannerViewHolder?, bean: PurchaseMemberModel, position: Int, size: Int) {
        holder?.apply {
            val iv = view.findViewById<ImageView>(R.id.imgItemBannerMember)
            val txtItemBannerMemberTitle = view.findViewById<TextView>(R.id.txtItemBannerMemberTitle)
            val txtItemBannerMemberContent = view.findViewById<TextView>(R.id.txtItemBannerMemberContent)
            iv.loadThumbnails(bean.img,iv.width)

            txtItemBannerMemberTitle.text = bean.title
            txtItemBannerMemberContent.text = bean.subTitle
        }
    }

    inner class BannerViewHolder(var view: View) : RecyclerView.ViewHolder(
        view
    )
}